package leetcode.day_2020_2021_1_25_2021_1_31;

/**
 * 7. 整数反转
 * https://leetcode-cn.com/problems/reverse-integer/
 */
public class LeetCode0007 {
    public static void main(String[] args) {
        System.out.println(reverse(1534236469));
    }

    public static int reverse(int x) {
        long result = 0l;
        int flag = 1;
        if (x < 0) {
            flag = -1;
            x = -x;
        }
        while (x != 0) {
            result = result*10 + x%10;
            x = x/10;
        }
        if (flag == -1) result = -result;
        if(result>Integer.MAX_VALUE || result<Integer.MIN_VALUE) return 0;
        return (int)result;
    }
}
